package com.igeek.shop.service.gouwuche;

import java.util.List;

import com.igeek.common.utils.CommonUtils;
import com.igeek.shop.dao.BaseDao;
import com.igeek.shop.entity.Area;
import com.igeek.shop.entity.Cart;
import com.igeek.shop.entity.CartItem;
import com.igeek.shop.entity.Gouwuche;
import com.igeek.shop.entity.Order;
import com.igeek.shop.entity.Product;

public class CartServiceImp implements CartService {

	private BaseDao<Product> dao = new BaseDao<Product>();
	@Override
	public Product query(String pid) {
		// TODO Auto-generated method stub
		String sql = "select * from product where pid = ?";
		Object[] params = {pid};
		Product product = (Product)dao.getUserByOne(sql, params, new Product());
		return product;
	}
	@Override
	public Cart getList(String username) {
		// TODO Auto-generated method stub
		return null;
	}
	
	//存入购物车数据
	@Override
	public void save(String pid ,int buyNum,double with,String username) {
		// TODO Auto-generated method stub
		String sql = "insert into gouwuche values(?,?,?,?,?)";
		Object[] params ={CommonUtils.getUUID(),pid,buyNum,with,username};
		BaseDao<Gouwuche> dao1 = new BaseDao<Gouwuche>();
		dao1.update(sql, params);
	}
	
	//拿到指定用户购物车中所有的信息
	@Override
	public List<Gouwuche> all(String username) {
		// TODO Auto-generated method stub
		BaseDao<Gouwuche>dao = new BaseDao<Gouwuche>();
		String sql = "select * from gouwuche where username = ?";
		Object[] params = {username};
		List<Gouwuche> gouwuche = (List<Gouwuche>) dao.getList(sql, params, new Gouwuche());
		return gouwuche;
	}
	@Override
	public void SetNumber(String pid, int qt,double newwith) {
		// TODO Auto-generated method stub
		BaseDao dao2 = new BaseDao();
		String sql = "UPDATE gouwuche SET  buynum=?,subtotal=?  where pid =?";
		Object[] params = {qt,newwith,pid};
		dao2.update(sql, params);
	}
	@Override
	public void delete(String pid) {
		// TODO Auto-generated method stub
		String sql = "DELETE FROM gouwuche WHERE pid = ? ";
		Object[] params = {pid};
		dao.update(sql, params);
	}
	@Override
	public void clearCart() {
		// TODO Auto-generated method stub
		String sql = "delete  from gouwuche";
		Object[] params = {};
		dao.update(sql, params);
	}
	@Override
	public void clearCart1(String username) {
		// TODO Auto-generated method stub
		String sql = "delete  from gouwuche where username=?";
		Object[] params = {username};
		dao.update(sql, params);
	}
	
	
	//根据id查询地址,三级联动
	@Override
	public Area inquireaddress(String pid) {
		// TODO Auto-generated method stub
		BaseDao<Area> dao = new BaseDao<Area>();
		String sql = "select * from area where id = ? ";
		Object[] params = {pid};
		Area address = (Area) dao.getUserByOne(sql, params, new Area());
		return address;
	}
	
	
	
	
	

}
